package com.yunmaozj.easydb.factory;

import com.yunmaozj.easydb.common.ClassUtil;

import javax.sql.DataSource;
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

/**
 * @author zhongminghong
 * @email yunmaozj@qq.com
 * @create 2018-05-27 22:31
 */
public  abstract class Factory extends Context{

    private DataSource dataSource;
    private Set<Class> primarySources;
    private Set<Class> classSources = new LinkedHashSet<>();

    public Factory(Class<?>[] classes,DataSource dataSource){
        this.dataSource = dataSource;
        this.primarySources = new LinkedHashSet<>(Arrays.asList(classes));
    }

    private void run(){
        if(primarySources != null){
            for(Class clazz : primarySources){
                try {
                    List<Class<?>> classList = ClassUtil.getClass(clazz.getPackage().getName());
                    classSources.addAll(classList);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
